package ypmits.components.buttons {
	import ypmits.components.Component;
	import ypmits.components.ComponentSkin;
	import ypmits.components.buttons.event.ButtonEvent;
	import ypmits.simpledraw.Cross;

	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Rectangle;

	/**
	 * @author Dave Lenz
	 */
	public class CloseButton extends Component {
		private var cross : Cross;

		
		public function CloseButton( size : Number = 20 ) {
			
			super( new ComponentSkin() );
			
			cross = new Cross( size, 4, 0xFFFFFF, "CENTER" );
			cross.rotation = -45;
			
			var closebutton : Sprite = new Sprite( );
			closebutton.x = ( width * .5 ) - 20;
			closebutton.y = -( height * .5 ) + 20;
			closebutton.buttonMode = true;
			closebutton.mouseChildren = false;
			closebutton.addChild( cross );
			closebutton.addEventListener( ButtonEvent.MOUSE_OVER, mouseOverHandler );
			closebutton.addEventListener( ButtonEvent.MOUSE_OUT, mouseOutHandler );
			
			var b : Rectangle = cross.getRect( this );
			var s : Shape = new Shape( );
			s.graphics.beginFill( 0xFF9900, 0 );
			s.graphics.drawRect( -( b.width * .5 ), -( b.height * .5 ), b.width, b.height );
			closebutton.addChild( s );
			
			addChild( closebutton );
		}

		
		public function mouseOverHandler(e : ButtonEvent) : void {
			var evt : ButtonEvent = new ButtonEvent( ButtonEvent.MOUSE_OVER );
			evt.displayobject = cross;
			dispatchEvent( evt );
		}

		
		public function mouseOutHandler(e : ButtonEvent) : void {
			var evt : ButtonEvent = new ButtonEvent( ButtonEvent.MOUSE_OUT );
			evt.displayobject = cross;
			dispatchEvent( evt );
		}
	}
}


class SingletonEnforcer {
}